package com.my.style.basemodul;

import android.content.Context;

import com.sv.jm.baselibrary.Config.AppConfig;
import com.sv.jm.baselibrary.Coustom.NetWorkException;
import com.sv.jm.baselibrary.http.HttpService;
import com.sv.jm.baselibrary.http.RetrofitHelper;

import java.util.Map;

import retrofit2.Retrofit;

/**
 * Created by 胡金辉 on 2017/5/24.
 */

public class HttpApi {
    private static HttpApi instance = null;
    Context ct;

    public static HttpApi getInstance(Context ct) {
        if (null == instance) {
            synchronized (HttpApi.class) {
                return new HttpApi(ct);
            }
        }
        return instance;
    }

    private HttpApi(Context ct) {
        this.ct = ct;
    }

    /**
     * 配置表单参数
     *
     * @param header
     * @return
     */
    public HttpService setHeader(Map<String, String> header) throws NetWorkException {
        Retrofit retrofit = RetrofitHelper.getInstance(ct).getRetrofit(getBaseUrl(), header);
        return retrofit.create(HttpService.class);
    }

    /**
     * 获取相应生产环境的url配置信息
     *
     * @return
     */
    private String getBaseUrl() {
        switch (AppConfig.DEVELOP_TYPE) {
            case InNetDev:
                return Comm.BASEURL;
            case OutNetTestDev:
                return Comm.BASEURL;
            case Nornal:
                return Comm.BASEURL;
            default:
                return Comm.BASEURL;
        }
    }

}
